package imdbfolder.gui.util;

import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.swing.JLabel;

public class Hyperlink extends JLabel {

    private static final long serialVersionUID = 1L;

    private final String url;

    public Hyperlink(String text, String url) {
        this.url = url;

        //setForeground(Color.BLUE);

        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

        setText("<html><u>" + text + "<u></html>");

        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                openUrl();
            }
        });
    }

    protected void openUrl() {
        try {
            Desktop.getDesktop().browse(new URI(url));
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch (URISyntaxException e) {
            e.printStackTrace();
        }
        //BareBonesBrowserLaunch.openURL(url);
    }
}
